
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class AppBarHomePage extends StatefulWidget {

  @override
  _AppBarHomePageState createState() => _AppBarHomePageState();
}

class _AppBarHomePageState extends State<AppBarHomePage> with SingleTickerProviderStateMixin {
   TabController tabController;
   List<String> list = ["首页","追番","历史"];
  @override
  void initState(){
    super.initState();
    tabController = new TabController(length: list.length, vsync: this);

  }
  // @override
  // void dispose(){
  //   tabController.dispose();
  //   super.dispose();
  // }
  // TabBarView getTabBarView(var tabs){
  //   return TabBarView(
  //     children: tabs,
  //     controller: tabController,
  //   );
  // }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("标题"),
        centerTitle: true,
        /// 左边的图标
        leading: Builder(builder: (BuildContext ctx){
          return IconButton(
              icon: Icon(Icons.home),
              onPressed: (){
                print("点击了左侧按钮");
                /// 打开左面的测拉菜单页面
                Scaffold.of(ctx).openDrawer();
              });
        }),
        /// 右侧按钮
        actions: <Widget>[
          IconButton(icon: Icon(Icons.message), onPressed: (){print("点击了消息按钮");}),
          IconButton(icon: Icon(Icons.share), onPressed: (){print("点击了分享按钮");}),
          IconButton(icon: Icon(Icons.close), onPressed: (){print("点击了关闭按钮");}),
        ],
        bottom: TabBar(
          tabs: list.map( (e)=> Tab(text: e) ).toList(),
          controller: tabController,
          /// 配置标签指示线的颜色
          indicatorColor: Colors.red,
          /// 配置高度
          indicatorWeight: 5.0,
          /// 配置标签指示线与边线距离
          indicatorPadding: EdgeInsets.all(1.0),
          /// 默认 平均分配宽度
          /// TabBarIndicatorSize.label 指示线与文字等宽
          indicatorSize: TabBarIndicatorSize.tab,
          /// 选中时label 文字颜色
          labelColor: Colors.yellow,
          labelStyle: TextStyle(color:Colors.green,fontSize: 14),
          /// 未选中label
          unselectedLabelColor: Colors.white,
          unselectedLabelStyle: TextStyle(color: Colors.deepPurple,fontSize: 12),

        ),

      ),
      body: TabBarView(
        controller: tabController,
        children: list.map((e){
          return Container(
            alignment: Alignment.center,
            child: Text(e),
          );
        }).toList(),
      ),
      drawer: Container(color: Colors.yellow, width: 250,),
    );
  }
}

